<?php namespace Phpcmf\Field;

class Yaoqiu extends \Phpcmf\Library\A_Field {
	
	/**
     * 构造函数
     */
    public function __construct() {
        parent::__construct();
		$this->fieldtype = ['TEXT' => '']; // TRUE表全部可用字段类型,自定义格式为 array('可用字段类型名称' => '默认长度', ... )
		$this->defaulttype = 'TEXT'; // 当用户没有选择字段类型时的缺省值
    }
	
	/**
	 * 字段相关属性参数
	 *
	 * @param	array	$value	值
	 * @return  string
	 */
	public function option($option) {

		return [''];
	}

    /**
     * 创建sql语句
     */
	/*public function create_sql($name, $value, $cname = '') {
	    $sql = 'ALTER TABLE `{tablename}` ADD `'.$name.'` TEXT NULL , ADD `'.$cname.'` TEXT NULL';
	    return $sql;
	}*/

    /**
     * 修改sql语句
     */
    public function alter_sql($name, $value, $cname = '') {
        return NULL;
    }

    /**
     * 删除sql语句
     */
    public function drop_sql($name) {
        return 'ALTER TABLE `{tablename}` DROP `'.$name.'`';
    }
	
	/**
	 * 字段输出
	 */
	public function output($value) {
		return $value;
	}
	
	/**
	 * 字段入库值
	 */
	public function insert_value($field) {
		$zus = \Phpcmf\Service::L('field')->post[$field['fieldname']];
		if($zus) {
			$zu = [
			'xueli' => $zus['xueli'],
			'gongling' => $zus['gongling'],
			'dinianling' => $zus['dinianling'],
			'gongnianling' => $zus['gongnianling'],
			'xingbie' => $zus['xingbie'],
			];
			
			\Phpcmf\Service::L('field')->data[$field['ismain']][$field['fieldname']] = dr_array2string($zu);
		}
		

	}

    /**
     * 字段表单输入
     *
     * @return  string
     */
    public function input($field, $value = []) {

        // 字段禁止修改时就返回显示字符串
        /*if ($this->_not_edit($field, $value)) {
            return $this->show($field, $value);
        }*/

        // 字段存储名称
        $name = $field['fieldname'];

        // 字段显示名称
        $text = ($field['setting']['validate']['required'] ? '<span class="required" aria-required="true"> * </span>' : '').$field['name'];

        // 表单附加参数
        $attr = $field['setting']['validate']['formattr'];

        // 字段提示信息
        $tips = ($name == 'title' && APP_DIR) || $field['setting']['validate']['tips'] ? '<span class="help-block" id="dr_'.$field['fieldname'].'_tips">'.$field['setting']['validate']['tips'].'</span>' : '';

        // 是否必填
        $required =  $field['setting']['validate']['required'] ? ' required="required"' : '';



        // 字段默认值
        $value = dr_string2array(\Phpcmf\Service::L('Field')->value[$field['fieldname']]);
	

        // 表单选项
        //$str = '<label><select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.']" id="dr_'.$name.'_ting" '.$attr.' >';
        //$str.= '<option value="0">'.dr_lang('选择分类').'</option>';
        //$options = \Phpcmf\Service::M('content', 'www')->son_type(\Phpcmf\Service::C()->index['son_type']);
		$wo = \Phpcmf\Service::C()->index['uid'];
		$uid = \Phpcmf\Service::C()->uid;

		$strs.= '
		<label>
			<select  '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.'][xueli]" id="dr_'.$name.'_xueli" '.$attr.' >
			
				<option value="1" '.(1 == $value['xueli'] ? ' selected' : '').'>本科</option>
				<option value="2" '.(2 == $value['xueli'] ? ' selected' : '').'>大专</option>
				<option value="3" '.(3 == $value['xueli'] ? ' selected' : '').'>中专</option>
				<option value="4" '.(4 == $value['xueli'] ? ' selected' : '').'>高中</option>
				<option value="8" '.(8 == $value['xueli'] ? ' selected' : '').'>初中</option>
				<option value="5" '.(5 == $value['xueli'] ? ' selected' : '').'>研究生</option>
				<option value="6" '.(6 == $value['xueli'] ? ' selected' : '').'>博士</option>
				<option value="7" '.(7 == $value['xueli'] ? ' selected' : '').'>不限</option>
			</select>
		</label>
		<label>
			<select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.'][gongling]" id="dr_'.$name.'_gongling" '.$attr.' >
			
				<option value="1" '.(1 == $value['gongling'] ? ' selected' : '').'>1年以上</option>
				<option value="2" '.(2 == $value['gongling'] ? ' selected' : '').'>2年以上</option>
				<option value="3" '.(3 == $value['gongling'] ? ' selected' : '').'>3年以上</option>
				<option value="4" '.(4 == $value['gongling'] ? ' selected' : '').'>4年以上</option>
				<option value="5" '.(5 == $value['gongling'] ? ' selected' : '').'>5年以上</option>
				<option value="6" '.(6 == $value['gongling'] ? ' selected' : '').'>6年以上</option>
				<option value="7" '.(7 == $value['gongling'] ? ' selected' : '').'>7年以上</option>
				<option value="8" '.(8 == $value['gongling'] ? ' selected' : '').'>8年以上</option>
				<option value="9" '.(9 == $value['gongling'] ? ' selected' : '').'>9年以上</option>
				<option value="10" '.(10 == $value['gongling'] ? ' selected' : '').'>10年以上</option>
				<option value="11" '.(11 == $value['gongling'] ? ' selected' : '').'>不限</option>
			
			</select>
		</label>
		
		<div>
		<label>
			<select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.'][dinianling]" id="dr_'.$name.'_dinianling" '.$attr.' >
		
				<option value="18" '.(18 == $value['dinianling'] ? ' selected' : '').'>18</option>
				<option value="16" '.(16 == $value['dinianling'] ? ' selected' : '').'>16</option>
				<option value="17" '.(17 == $value['dinianling'] ? ' selected' : '').'>17</option>
				<option value="20" '.(20 == $value['dinianling'] ? ' selected' : '').'>20</option>
				<option value="23" '.(23 == $value['dinianling'] ? ' selected' : '').'>23</option>
				<option value="25" '.(25 == $value['dinianling'] ? ' selected' : '').'>25</option>
				<option value="30" '.(30 == $value['dinianling'] ? ' selected' : '').'>30</option>
				<option value="35" '.(35 == $value['dinianling'] ? ' selected' : '').'>35</option>
				<option value="40" '.(40 == $value['dinianling'] ? ' selected' : '').'>40</option>
				<option value="45" '.(45 == $value['dinianling'] ? ' selected' : '').'>45</option>
				<option value="50" '.(50 == $value['dinianling'] ? ' selected' : '').'>50</option>
				<option value="55" '.(55 == $value['dinianling'] ? ' selected' : '').'>55</option>
				<option value="60" '.(60 == $value['dinianling'] ? ' selected' : '').'>60</option>
				<option value="61" '.(61 == $value['dinianling'] ? ' selected' : '').'>60以上</option>
		
			</select>
		</label>
		<label>
			<select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.'][gongnianling]" id="dr_'.$name.'_gongnianling" '.$attr.' >
				<option value="0" '.(0 == $value['gongnianling'] ? ' selected' : '').'>留空</option>
				<option value="18" '.(18 == $value['gongnianling'] ? ' selected' : '').'>18</option>
				<option value="20" '.(20 == $value['gongnianling'] ? ' selected' : '').'>20</option>
				<option value="25" '.(25 == $value['gonggnianling'] ? ' selected' : '').'>25</option>
				<option value="30" '.(30 == $value['gongnianling'] ? ' selected' : '').'>30</option>
				<option value="35" '.(35 == $value['gongnianling'] ? ' selected' : '').'>35</option>
				<option value="40" '.(40 == $value['gongnianling'] ? ' selected' : '').'>40</option>
				<option value="45" '.(45 == $value['gongnianling'] ? ' selected' : '').'>45</option>
				<option value="50" '.(50 == $value['gongnianling'] ? ' selected' : '').'>50</option>
				<option value="55" '.(55 == $value['gongnianling'] ? ' selected' : '').'>55</option>
				<option value="60" '.(60 == $value['gongnianling'] ? ' selected' : '').'>60</option>
				<option value="61" '.(61 == $value['gongnianling'] ? ' selected' : '').'>60以上</option>
			</select>
		</label>
		<span class="d-zuo-10">年龄</span>
		</div>
		<div>
		    <label>
		    	<select '.$required.' class="form-control '.$field['setting']['option']['css'].'" name="data['.$name.'][xingbie]" id="dr_'.$name.'_xingbie" '.$attr.' >
		    		<option value="10" '.(10 == $value['xingbie'] ? ' selected' : '').'>男女不限</option>
					<option value="1" '.(1 == $value['xingbie'] ? ' selected' : '').'>男</option>
		    		<option value="2" '.(2 == $value['xingbie'] ? ' selected' : '').'>女</option>
					
		    		
		    	</select>
		    </label>
		    <span class="d-zuo-10">性别</span>
		</div>
		

		';

        $str.= $strs;
        return $this->input_format($name, $text, $str);
    }



    /**
     * 字段表单显示
     *
     * @param	string	$field	字段数组
     * @param	array	$value	值
     * @return  string
     */
    public function show($field, $value = null) {

        $options = dr_format_option_array($field['setting']['option']['options']);

        $str = '<div class="form-control-static"> '.(isset($options[$value]) ? $options[$value] : dr_lang('未选择')).' </div>';

        return $this->input_format($field['fieldname'], $field['name'], $str);
    }
}